package com.pinyoumei.app.utils;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.pinyoumei.app.R;

/**
 * SharedPreferences 工具保存类
 */
public class SPUtils {

    public static  String [] bankName =  new String[]{"工商银行","农业银行","中国银行","建设银行","交通银行","中信银行","光大银行","华夏银行","民生银行","广发银行","招商银行","浦发银行","邮储银行","北京银行","兴业银行","平安银行","上海银行"};
    public static  String [] bankCord =  new String[]{"ICBC","ABC","BOC","CCB","BOCO","CITIC","CEB","HXB","CMBC","CGB","CMBCHINA","SPDB","PSBC","BCCB","CIB","SDB","SHYH"};
    public static  int [] bankIcon =  new int[]{R.mipmap.icon_gsyh,R.mipmap.icon_nyyh,R.mipmap.icon_zgyh,R.mipmap.icon_jsyh,R.mipmap.icon_jtyh,R.mipmap.icon_zxhh,R.mipmap.icon_gdhh,R.mipmap.icon_hhyh,R.mipmap.icon_msyh,R.mipmap.icon_gfyh,R.mipmap.icon_zsyh,R.mipmap.icon_pfyh,R.mipmap.icon_ycyh,R.mipmap.icon_bjyh,R.mipmap.icon_xyyh,R.mipmap.icon_payh,R.mipmap.icon_shyh};

    public static String getBankName(String bn){
        String bnm = "";
        for (int i = 0; i < bankName.length; i++) {
            if(bankName[i].equals(bn)){
                bnm = bankName[i];
                break;
            }else {
                bnm = "";
            }
        }
        return bnm;
    }

    public static String getBankCord(String bn){
        String bnm = "";
        for (int i = 0; i < bankName.length; i++) {
            if(bankName[i].equals(bn)){
                bnm = bankCord[i];
                break;
            }else {
                bnm = "";
            }
        }
        return bnm;
    }

    public static void setChannelId(Context context,String imgStr){
        SharedPreferences sharedPreferences = context.getSharedPreferences("ChannelId", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putString("ChannelId",imgStr).commit();
    }

    public static String getChannelId(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("ChannelId", Activity.MODE_PRIVATE);
        return sharedPreferences.getString("ChannelId","");
    }


    public static void setRuleType(Context context,int imgStr){
        SharedPreferences sharedPreferences = context.getSharedPreferences("RuleType", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putInt("RuleType",imgStr).commit();
    }

    public static int getRuleType(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("RuleType", Activity.MODE_PRIVATE);
        return sharedPreferences.getInt("RuleType",0);
    }


    public static void setBottomImg(Context context,String imgStr){
        SharedPreferences sharedPreferences = context.getSharedPreferences("imgStr", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putString("imgStr",imgStr).commit();
    }

    public static String getBottomImg(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("imgStr", Activity.MODE_PRIVATE);
        return sharedPreferences.getString("imgStr","s");
    }

    public static void setWxKey(Context context,String appkey){
        SharedPreferences sharedPreferences = context.getSharedPreferences("wxAppKey", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putString("wxAppKey",appkey).commit();
    }

    public static String getWxKey(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("wxAppKey", Activity.MODE_PRIVATE);
        return sharedPreferences.getString("wxAppKey","");
    }

    public static String getJPushKey(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("JPushKey", Activity.MODE_PRIVATE);
        return sharedPreferences.getString("JPushKey","");
    }

    public static void setJPushKey(Context context,String JPush){
        SharedPreferences sharedPreferences = context.getSharedPreferences("JPushKey", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putString("JPushKey",JPush).commit();
    }

    /**
     * 是否设置交易密码
     */
    public static void setPayPassword(Context context,boolean isSet){
        SharedPreferences sharedPreferences = context.getSharedPreferences("PayPassword", Activity.MODE_PRIVATE);
        sharedPreferences.edit().putBoolean("PayPassword",isSet).commit();
    }

    public static boolean isPayPassword(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("PayPassword", Activity.MODE_PRIVATE);
        return sharedPreferences.getBoolean("PayPassword",false);
    }

    /**
     * 首页数据是否更新
     */
    public static boolean isNewHomeData(Context context,String homeData){
        SharedPreferences sharedPreferences = context.getSharedPreferences("HomeData", Activity.MODE_PRIVATE);

        String oldData = sharedPreferences.getString("HomeData","unfind");

        if (!oldData.equals(homeData)){
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("HomeData",homeData);
            editor.commit();
            return true;
        }

        return false;
    }

    /**
     * 更新首页
     */
    public static void clearHomeData(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("HomeData",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    /**
     * 设置推送开关
     */
    public static void setIsPush(Context context,boolean isPush){
        SharedPreferences sharedPreferences = context.getSharedPreferences("isPush",Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isPush",isPush);
        editor.commit();
    }
    /**
     * 是否开启推送
     */
    public static boolean isPush(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("isPush",Activity.MODE_PRIVATE);
        return sharedPreferences.getBoolean("isPush",true);
    }
    /**
     * 第一次使用的保存信息
     * @param context
     * @param bool
     */
    //该方法设置用户是否是第一次使用 以便做引导页面的逻辑处理
    public static void setIsFirstUse(Context context,boolean bool){
        SharedPreferences sharedPreferences = context.getSharedPreferences("FirstUse", Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("firstUse",bool);
        editor.commit();
    }
    //该方法活得用户是否第一次使用 返回一个bool类型
    public static boolean getIsFirstUse(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("FirstUse",Activity.MODE_PRIVATE);
        return sharedPreferences.getBoolean("firstUse",true);
    }
    /**
     * 用户user_id的保存信息
     * @param context
     * @param app_user_id
     */
    //保存用户的user_id 第一次登录保存了token 以后进入app只要有token的话就直接进入主界面
    public static void saveAppUserId(Context context,String app_user_id){
        SharedPreferences sharedPreferences = context.getSharedPreferences("token",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("app_user_id",app_user_id);
        editor.commit();
    }
    //获取用户user_id
    public static String getAppUserId(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("token",Activity.MODE_PRIVATE);
        return sharedPreferences.getString("app_user_id","");//没有拿到用户id就赋值为""
    }
    //清除用户user_id
    public static void clearAppUserid(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("token",Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    /**
     * 用户登录信息保存
     * @param context
     * @param username
     * @param password
     */
    //保存用户登录信息
    public static void saveUserLoginInfor(Context context,String username,String password){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserLoginInfor",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("username",username);
        editor.putString("password",password);
        editor.commit();
    }
    //获取用户登录信息 Editor
    public static SharedPreferences getUserLoginInfor(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserLoginInfor",Context.MODE_PRIVATE);
        return sharedPreferences;
    }
    //清除用户登录信息
    public static void clearUserLoginInfor(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserLoginInfor",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    /**
     * 保存用户手机号信息
     * @param context
     * @param phone
     */
    //保存用户手机号
    public static void saveUserPhone(Context context,String phone){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserPhone",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("phone",phone);
        editor.commit();
    }
    //获取用户手机号
    public static String  getUserPhone(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserPhone",Context.MODE_PRIVATE);
        return sharedPreferences.getString("phone","");
    }
    //清除用户手机号
    public static void  clearUserPhone(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("UserPhone",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    //保存用户的支付宝账号信息
    public static void saveAlipayAccountInfo(Context context,String username,String account){
        SharedPreferences sharedPreferences = context.getSharedPreferences("alipay",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("username",username);
        editor.putString("account",account);
        editor.commit();
    }
    //保存用户的银行卡账号信息
    public static void saveBankAccountInfo(Context context,String username,String account){
        SharedPreferences sharedPreferences = context.getSharedPreferences("bank",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("username",username);
        editor.putString("account",account);
        editor.commit();
    }
    //清除用户支付宝账号信息
    public static void clearAlipayAccountInfo(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("alipay",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    //清除用户银行卡账号信息
    public static void clearBankAccountInfo(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("bank",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    //保存启动页加载图片
    public static void saveSplashImageUrl(Context context,String url){
        SharedPreferences sharedPreferences = context.getSharedPreferences("Splash",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("url",url);
        editor.commit();
    }
    //获取启动页加载图片
    public static String getSplashImageUrl(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("Splash",Context.MODE_PRIVATE);
        return sharedPreferences.getString("url","");
    }

    //保存登录页加载图片
    public static void saveloginImageUrl(Context context,String url){
        SharedPreferences sharedPreferences = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("url",url);
        editor.commit();
    }
    //获取登录页加载图片
    public static String getloginImageUrl(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("login",Context.MODE_PRIVATE);
        return sharedPreferences.getString("url","");
    }

    /**
     * 保存一个本地时间戳
     */
    public static void saveTimeStamp(Context context,String time_stamp){
        SharedPreferences sharedPreferences = context.getSharedPreferences("time_stamp",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("time_stamp",time_stamp);
        editor.commit();
    }
    /**
     * 获取本地时间戳
     */
    public static String getTimeStamp(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("time_stamp",Context.MODE_PRIVATE);
        return sharedPreferences.getString("time_stamp","");
    }
    /**
     * 清除本地时间戳
     */
    public static void clearTimeStamp(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("time_stamp",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
    //保存一个日期时间字符串
    public static void saveTimeString(Context context,String timeString){
        SharedPreferences sharedPreferences = context.getSharedPreferences("timeString",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("timeString",timeString);
        editor.commit();
    }
    //获取一个日期时间字符串
    public static String getTimeString(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("timeString",Context.MODE_PRIVATE);
        return sharedPreferences.getString("timeString","");
    }
    //清除一个日期时间字符串
    public static void clearTimeString(Context context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("timeString",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.clear();
        editor.commit();
    }
}
